Skip to content

Fix Windows MSVC build failure during ABI generation#388

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-windows-build-failure
Draft

Fix Windows MSVC build failure during ABI generation#388
Copilot wants to merge 5 commits intomainfrom
copilot/fix-windows-build-failure

Conversation

Copy link
Contributor

Copilot AI commented Jan 14, 2026

cargo near build fails on Windows with 55 unresolved external symbol linker errors (LNK2019) during ABI generation. The build succeeds with --no-abi.

Root Cause

ABI generation compiles the contract as a native dylib with near-sdk/__abi-generate. The near-sys crate declares NEAR runtime functions (read_register, register_len, etc.) as extern "C" - these are provided by the NEAR VM in wasm builds but don't exist in native builds. MSVC's linker rejects unresolved symbols by default, unlike Linux/macOS dynamic linkers.

Changes

  • Add Windows linker flag: Pass /FORCE:UNRESOLVED to MSVC linker when building ABI dylib, allowing unresolved symbols (safe since the dylib is only loaded for symbol extraction, never executed)

  • Fix RUSTFLAGS handling: Refactor cargo_native::compile::run to append -Awarnings to existing RUSTFLAGS instead of replacing them, ensuring Windows linker flag is preserved

// cargo-near-build/src/near/abi/generate/mod.rs
#[cfg(windows)]
{
    compile_env.push((env_keys::RUSTFLAGS, "-C link-arg=/FORCE:UNRESOLVED"));
}

The dylib is temporary and only used for ABI extraction via libloading - unresolved symbols never cause runtime issues.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • s3-us-west-1.amazonaws.com
    • Triggering command: /home/REDACTED/work/cargo-near/cargo-near/target/debug/build/near-workspaces-a8b4a713a403149e/build-script-build /home/REDACTED/work/cargo-near/cargo-near/target/debug/build/near-workspaces-a8b4a713a403149e/build-script-build --gdwarf-4 --64 --noexecstack -o crypto/x509/libcrypto-lib-v3_bitst.o /tmp/cccbl4ru.s /usr/sbin/cc AES_ASM -DECP_NIas /home/REDACTED/wor-I (dns block)
    • Triggering command: /home/REDACTED/work/cargo-near/.codeql-scratch/dbs/rust/working/target/debug/build/near-workspaces-2094825312d8cd28/build-script-build /home/REDACTED/work/cargo-near/.codeql-scratch/dbs/rust/working/target/debug/build/near-workspaces-2094825312d8cd28/build-script-build - -o /rust/working/ta-I N /rust/working/ta--gdwarf-4 .o cal/bin/cc 6e14519a1242e/oucc -gdwarf-4 -fno-omit-frame--c /rust/working/ta-o -O0 rget/debug/build-x rget/debug/buildassembler rget/debug/build/dev/null rget/debug/build/home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/bin/rustc rget/debug/build--crate-name pointer as (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Windows (without WSL) build failure on ABI generation step</issue_title>
<issue_description>after installing binary release from latest https://github.com/near/cargo-near/releases/tag/cargo-near-v0.6.4 tag
with

irm https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.ps1 | iex

onto
image
image

a cargo near build command fails for a default project, generated by cargo near new:
image
image
image

A standalone cargo build --features near-sdk/__abi-generate command fails with similar error (with and without --release).


A cargo near build --no-abi succeeds:
image
As well as standalone cargo build --target wasm32-unknown-unknown (with and without --release).

</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits January 14, 2026 01:11
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Windows build failure during ABI generation Fix Windows MSVC build failure during ABI generation Jan 14, 2026
Copilot AI requested a review from r-near January 14, 2026 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows (without WSL) build failure on ABI generation step

2 participants